﻿@model AdminUserDTO[]
@{
    ViewBag.Title = "管理员管理";
}

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span class="c-gray en">&gt;</span> 管理员列表 <a class="btn btn-success radius r btn-refresh" style="line-height:1.6em;margin-top:3px" href="javascript:;" onclick="javascript: location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="text-c">
        <form id="formSeach" action="/Webadmin/AdminUser/List" method="get">
            日期范围：
            <input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'BeginDate\')||\'%y-%M-%d\'}' })" id="BeginDate" name="BeginDate" class="input-text Wdate" style="width:120px;">
            -
            <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'EndDate\')}',maxDate:'%y-%M-%d' })" id="EndDate" name="EndDate" class="input-text Wdate" style="width:120px;">
            <input type="text" class="input-text" style="width:250px" placeholder="关键字" id="Keywords" name="Keywords">
            <button type="submit" class="btn btn-success" id="btnSeach"><i class="Hui-iconfont">&#xe665;</i> 查询</button>
        </form>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="batch_del()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> <a href="javascript:;" onclick=" layer_show('添加管理员', '/Webadmin/AdminUser/Add' , '800' , '500' )" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加管理员</a></span> <span class="r">共有数据：<strong>@ViewBag.totalCount</strong> 条</span></div>
    <form id="formList">
        <table class="table table-border table-bordered table-hover table-bg">
            <thead>
                <tr>
                    <th scope="col" colspan="8">管理员列表</th>
                </tr>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" name="" value=""></th>
                    <th width="40">ID</th>
                    <th width="150">登录名</th>
                    <th>角色</th>
                    <th width="130">加入时间</th>
                    <th width="100">是否已启用</th>
                    <th width="100">操作</th>
                </tr>
            </thead>
            <tbody>
                @{
                    foreach (var user in Model)
                    {
                        <tr class="text-c">
                            <td><input type="checkbox" value="@user.Id" name="selectdIds"></td>
                            <td>@user.Id</td>
                            <td>@user.Name</td>
                            <td>@user.RoleNames</td>
                            <td>@user.CreateDateTime</td>
                            @if (user.IsEnable)
                            {
                                <td class="td-status"><span class="label label-success radius">已启用</span></td>
                            }
                            else
                            {
                                <td class="td-status"><span class="label radius">已停用</span></td>
                            }
                            <td class="td-manage">
                                @if (user.IsEnable)
                                {
                                    <a style="text-decoration:none" onClick="admin_stop(this,@user.Id)" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>
                                }
                                else
                                {
                                    <a style="text-decoration:none" onClick="admin_start(this,@user.Id)" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe615;</i></a>
                                }
                                <a title="设置特殊权限" href="javascript:;" onclick="layer_show('设置特殊权限', '/Webadmin/AdminUser/SetPermission?id=@user.Id', '800', '500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe70d;</i></a>
                                <a title="编辑" href="javascript:;" onclick="layer_show('管理员编辑', '/Webadmin/AdminUser/Edit?id=@user.Id', '800', '500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                                <a title="删除" href="javascript:;" onclick="admin_del(this, @user.Id)" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                            </td>
                        </tr>
                    }
                }
            </tbody>
        </table>
    </form>
    @{
            var pager = new DotNetMVC.Common.CommonPager();
            pager.CurrentPageClassName = "active";
            pager.MaxPagerCount = (int)ViewBag.maxPagerCount;
            pager.PageIndex = (int)ViewBag.pageIndex;//这些数据，cshtml不知道，就必须让Action传递给我们
                                                     //对于所有cshtml要用到，但是又获取不到的数据，都由Action来获取，然后放到ViewBag或者Model中传递给cshtml
            pager.PageSize = (int)ViewBag.pageSize;
            pager.TotalCount = (int)ViewBag.totalCount;
            pager.UrlPattern = "/WebAdmin/AdminUser/List?pageIndex={pn}";
        }
        <div id="pager">
            @Html.Raw(pager.GetPagerHtml()) 
        </div>
</div>
@section FooterScript
{
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script type="text/javascript">
        /*批量删除*/
        function batch_del() {
            layer.confirm("确认要批量删除吗？", function () {
                var formData = $("#formList").serializeArray();
                $.ajax({
                    url: "/WebAdmin/AdminUser/BatchDelete",
                    type: "post",
                    data: formData,
                    dataType: "json",
                    success: function (res) {
                        if (res.status == "ok") {
                            layer.msg('已批量删除!', { icon: 1, time: 2000 }, function () {
                                $(".btn-refresh").click();
                            });
                        } else if (res.status == "redirect") {
                            location.href = res.data;
                        } else if (res.status == "error") {
                            layer.msg(res.errorMsg, { icon: 2, time: 1000 });
                        }else {
                            layer.msg("批量删除失败", { icon: 2, time: 1000 });
                        }
                    },
                    error: function () {
                        layer.msg('网络出错!', { icon: 2, time: 2000 });
                    }
                });
            });
        }

        /*删除*/
        function admin_del(obj, id) {
            layer.confirm('确认要删除吗？', function (index) {
                $.ajax({
                    type: 'POST',
                    url: '/WebAdmin/AdminUser/Delete',
                    data: { id: id },
                    dataType: 'json',
                    success: function (res) {
                        if (res.status == "ok") {
                            layer.msg('已删除!', { icon: 1, time: 2000 }, function () {
                                $(".btn-refresh").click();
                            });
                        } else if (res.status == "redirect") {
                            location.href = res.data;
                        } else if (res.status == "error") {
                            layer.msg(res.errorMsg, { icon: 2, time: 1000 });
                        }else {
                            layer.msg("删除失败", { icon: 2, time: 1000 });
                        }
                    },
                    error: function (data) {
                        layer.msg('网络出错!', { icon: 2, time: 2000 });
                    },
                });
            });
        }
        /*管理员-停用*/
        function admin_stop(obj,id){
            layer.confirm('确认要停用吗？',function(index){
                $.ajax({
                    url: "/WebAdmin/AdminUser/DisableAdminUser",
                    type: "post",
                    data: {id:id},
                    dataType: "json",
                    success: function (res) {
                        if (res.status == "ok") {
                            layer.msg('已停用!', { icon: 1, time: 2000 }, function () {
                                $(".btn-refresh").click();
                            });
                        } else if (res.status == "redirect") {
                            location.href = res.data;
                        } else if (res.status == "error") {
                            layer.msg(res.errorMsg, { icon: 2, time: 1000 });
                        }else {
                            layer.msg("停用失败", { icon: 2, time: 1000 });
                        }
                    },
                    error: function () {
                        layer.msg('网络出错!', { icon: 2, time: 2000 });
                    }
                });
            });
        }

        /*管理员-启用*/
        function admin_start(obj,id){
            layer.confirm('确认要启用吗？',function(index){
                $.ajax({
                    url: "/WebAdmin/AdminUser/EnableAdminUser",
                    type: "post",
                    data: {id:id},
                    dataType: "json",
                    success: function (res) {
                        if (res.status == "ok") {
                            layer.msg('已启用!', { icon: 1, time: 2000 }, function () {
                                $(".btn-refresh").click();
                            });
                        } else if (res.status == "redirect") {
                            location.href = res.data;
                        } else if (res.status == "error") {
                            layer.msg(res.errorMsg, { icon: 2, time: 1000 });
                        }else {
                            layer.msg("启用失败", { icon: 2, time: 1000 });
                        }
                    },
                    error: function () {
                        layer.msg('网络出错!', { icon: 2, time: 2000 });
                    }
                });
            });
        }
    </script>
}

